﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyProjectPerformances : YuanlinUserControl,
        IReplyConverter<CompanyProjectPerformanceReply, GetListOperation>
    {
        protected Repeater list;
        protected Pager pager;
        protected CurrentPage currentPage;
        private EntityList companyProjectPerformances;
        public string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            CompanyProjectPerformanceListRequest request = new CompanyProjectPerformanceListRequest();
            request.UserId = UserIdFromGreenNum;
            request.PageIndex = pager.PageIndex;
            request.PageSize = pager.PageSize;
            requestBinders.Add(RequestHelper.BuildGetCompanyProjectPerformanceListRequest(this, request));
        }

        private void BindData()
        {
            list.DataSource = companyProjectPerformances;
            list.DataBind();

            if (pager != null && currentPage != null)
            {
                pager.TotalPages = pager.CalculateTotalPages(companyProjectPerformances.TotalCount);
                currentPage.TotalRecords = (companyProjectPerformances.TotalCount);
                currentPage.TotalPages = pager.TotalPages;
                currentPage.PageIndex = pager.PageIndex;
            }
        }

        #region IReplyConverter<CompanyProjectPerformanceReply,GetListOperation> Members

        public void ConvertReply(CompanyProjectPerformanceReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                companyProjectPerformances = reply.EntityList;

                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
